<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: acer
  Date: 2018/12/17
  Time: 18:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../js/jquery.min.3.1.0.js"></script>
    <style>
        .layui-form-checkbox[lay-skin=primary] i {
            position: relative;
            top: 7px;
        }
    </style>
</head>
<body>

<div class="demoTable">
    <button class="layui-btn " data-type="isOk">确认选择</button>
</div>

<table class="layui-table" lay-data="{width: 435, height:480, url:'/SeleWareServlet', page:false, id:'idTest'}"
       lay-filter="demo">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
        <th lay-data="{type:'numbers',width:80, fixed: 'left'}">序号</th>
        <%--<th lay-data="{type:'id', width:80, sort: true}">主键ID</th>--%>
        <th lay-data="{field:'goName', width:180}">商品名称</th>
        <th lay-data="{field:'goPrice', width:120, sort: true}">商品售价</th>
    </tr>
    </thead>
</table>

<script src="../../layuiadmin/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>

    layui.use('table', function () {
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demo)', function (obj) {
            console.log(obj)
        });

        //监听单元格编辑
        table.on('edit(test)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            layer.msg('[ID: ' + data.noticeId + '] ' + field + ' 字段更改为：' + value);
        });

        var $ = layui.$, active = {
            isOk: function () {
                var checkStatus = table.checkStatus('idTest')
                    , data = checkStatus.data;
                var objs = eval(data);
                if (objs.length != null && "" != objs.length) {
                    var names = "";
                    var fmoneys = 0;
                    var ids = "";
                    for (var j = 0; j < objs.length; j++) {
                        names += objs[j].goName + ",";
                        fmoneys += parseInt(objs[j].goPrice);
                        ids += objs[j].goId + ",";
                    }
                    layer.confirm('订单总价: ' + fmoneys + ', 确认商品总价？', function (index) {
                        parent.document.getElementById("wareName").value=names;
                        parent.document.getElementById("price").value=fmoneys;
                        parent.document.getElementById("wareId").value=ids;
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                } else {
                    layer.alert("至少选择一项")
                }
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });
</script>
</body>
</html>